package com.example.remoteviewdemo;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RemoteViews;

public class ActivityB extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_b);
        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sendRemoteViews();
            }
        });
    }

    private void sendRemoteViews() {
        RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification);
        remoteViews.setTextViewText(R.id.title, "msg from perocess:" + android.os.Process.myPid());
        remoteViews.setImageViewResource(R.id.img, R.mipmap.ic_launcher);
        PendingIntent pedningIntent2 = PendingIntent.getActivity(this, 0, new Intent(this, SecondActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
        PendingIntent pedningIntent3 = PendingIntent.getActivity(this, 0, new Intent(this, SecondActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.title, pedningIntent2);
        remoteViews.setOnClickPendingIntent(R.id.img, pedningIntent3);

        Intent intent = new Intent("gaga");
        intent.putExtra("remoteviews", remoteViews);
        sendBroadcast(intent);
    }
}
